package com.example.demo.Controller;
import com.example.demo.Service.UserService;
import com.example.demo.userdemo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/get")
    public ResponseEntity<User> getUser(@RequestBody User user) {
        User result = userService.getUser(user);
        return ResponseEntity.ok(result);
    }

    @PutMapping("/update")
    public ResponseEntity<User> updateUser(@RequestBody User user) {
        User updatedUser = userService.updateUser(user);
        return ResponseEntity.ok(updatedUser);
    }

    @DeleteMapping("/delete")
    public ResponseEntity<?> deleteUsers(@RequestBody List<Long> ids) {
        userService.deleteUsers(ids);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/addBatch")
    public ResponseEntity<List<User>> addUsers(@RequestBody List<User> users) {
        List<User> savedUsers = userService.addUsers(users);
        return ResponseEntity.ok(savedUsers);
    }
}
